<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script>


//【示例1】方法调用模式。

var obj = {
    value : 0,
    increment : function(inc) {
        this.value += typeof inc === 'number' ? inc : 1;
    }
}
obj.increment();
document.writeln(obj.value); 	// 1
obj.increment(2);
document.writeln(obj.value);	// 3
//【示例2】函数调用模式。

var sum = add(3, 4); 	//7


var obj = {
    value : 1,
    doub : function() {
        var that = this;
        var helper = function() {
            that.value = that.value * 2;
        };
        helper();
    }
}
obj.doub();
document.writeln(obj.value); 	// 2
//【示例3】构造器调用模式。

var F = function(string) { 
    this.status = string;
};
F.prototype.get = function() {
    return this.status;
};
var f = new F("new object");
document.writeln(f.get());	//"new object"
//【示例4】apply调用模式。

var array = [5, 4]; 
var add = function() {
    var i, sum = 0;
    for( i = 0; i < arguments.length; i += 1) {
        sum += arguments[i];
    }
    return sum;
};
var sum = add.apply({}, array); 	// 9

var F = function(string) { 
    this.status = string;
};
F.prototype.get = function() {
    return this.status;
};
var obj = { 
    status: 'obj' 
}; 
var status = F.prototype.get.apply(obj); 	//''obj''



</script>
</head>
<body>




</body>
</html>
